@extends('admin.layout.base')

@section('content')
    <div class="layui-form-item">
        <div class="layui-inline">
            <input class="layui-input search-data" name="title" placeholder="标题" autocomplete="off">
        </div>

        <div class="layui-inline layui-form">
            <select name="status" class="search-data">
                <option value="">状态</option>
                <option value="0">启用</option>
                <option value="1">停用</option>
            </select>
        </div>

        <div class="layui-inline demoTable">
            <button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin" data-type="search" lay-filter="search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>

            @can('webNews.create')
            <button data-url="{{route("webNews.create")}}" data-type="openViews" data-width="100%" data-height="100%" class="layui-btn layui-btn-sm">添 加</button>
            @endcan
        </div>
    </div>

    <div class="layui-card">

        <table class="layui-hide" id="tableData" lay-filter="myTable"></table>

        <script type="text/html" id="admin">
            @{{d.get_admin.name}}
        </script>

        <script type="text/html" id="status">
            <a lay-event="status">
                <input type="checkbox" data-url="{{route("webNews.status")}}" data-id="switch_@{{d.id}}" value="@{{d.status}}" @{{d.status==0?'checked':''}} lay-skin="switch" lay-text="启用|停用">
            </a>
        </script>

        <script type="text/html" id="options">
            <div class="layui-btn-group">
                @can('webNews.edit')
                <a data-url="{{route("webNews.edit")}}" lay-event="edit" data-width="100%" data-height="100%" class="layui-btn layui-btn-xs layui-btn-normal">编辑</a>
                @endcan
                @can('webNews.delete')
                <a data-url="{{route("webNews.delete")}}" lay-event="del" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
                @endcan
            </div>
        </script>

    </div>
@endsection

@section('script')
    <script>
        layui.use(['table', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var table = layui.table;
            table.render({
                elem: '#tableData'
                , url: '{{route("webNews.list")}}'
                , cols: [[
                    {field: 'id', title: 'ID', sort: true, width: 60}
                    , {field: 'title', title: '新闻标题'}
                    , {field: 'get_admin', title: '发布者', width: 150, toolbar: '#admin'}
                    , {field: 'browse', title: '浏览量', width: 100}
                    , {field: 'created_at', title: '创建时间', width: 180}
                    , {field: 'status', fixed: 'right', title: '状态', toolbar: '#status', width: 120}
                    , {fixed: 'right', width: 120, title: '操作', align: 'center', toolbar: '#options'}
                ]]
                , id: 'myReload'
                , page: true
            });
        });
    </script>
@endsection